
@ECHO OFF

::To use the batch file, uzip ProjectX.zip and add to your Perforce root; 
::this assumes the root is called depot, so the structure will be //depot/ProjectX/MAIN/source

::set up variables:
set branchName=ProjectX_MAIN-R1
set mainView=//depot/ProjectX/MAIN/...
set branchView=//depot/ProjectX/R1/...

set masterClient=MASTER
set branchClient=ProjectX_R1-MASTER

set branchClientView=//ProjectX_R1-MASTER/...
set branchClientRoot=c:\depot\ProjectX\R1
set label= 

::generate spec form for the branch:
set branchSpecPath=C:\%branchName%.p4
GenerateP4SpecForm "WRITE" "%branchSpecPath%" "|" "Branch: %branchName%|Owner:	elton.stoneman|Description: Created by elton.stoneman.|Options:	unlocked|View: %mainView% %branchView%"

::create the branch view:
p4 branch -i <%branchSpecPath%

::generate spec form for the branch master workspace:
set branchClientSpecPath=C:\%branchClient%.p4
GenerateP4SpecForm "WRITE" "%branchClientSpecPath%" "|" "Client: %branchClient%|Owner: elton.stoneman|Host: ESLPC347|Description: Created by elton.stoneman.|Root: %branchClientRoot%|Options: noallwrite noclobber nocompress unlocked nomodtime normdir|SubmitOptions: submitunchanged|LineEnd: local|View: %branchView% %branchClientView%"

::create branch workspace:
p4 client -i <%branchClientSpecPath%

::integrate the branch back to main - branch to label if provided:
IF "%label%"==" " p4 -c%branchClient% integrate -b %branchName%
IF NOT "%label%"==" " p4 -c%branchClient% integrate -b %branchName% @%label%

::get a list of the changes (required for Submit):
set changePath=c:\%branchClient%.chg
p4 -c%branchClient% change -o >%changePath%
IF "%label%"==" " GenerateP4SpecForm "UPDATE" "%changePath%" "<enter description here>" "MASTER created from branch: %branchName%"
IF NOT "%label%"==" " GenerateP4SpecForm "UPDATE" "%changePath%" "<enter description here>" "MASTER created from branch: %branchName%, label: %label%"

::submit to create branch in depot:
p4 -c%branchClient% submit -i <%changePath%
